import pandas as pd  # 将pandas作为第三方库导入，我们一般为pandas取一个别名叫做pd

pd.set_option('expand_frame_repr', False)  # 当列太多时清楚展示

# =====导入数据
df = pd.read_csv(
    filepath_or_buffer=r'../../data/a_stock_201903.csv',
    encoding='gbk'
)
# print(df['收盘价'])
df['收盘价_3天均值'] = df['收盘价'].rolling(3).mean()
# print(df[['收盘价', '收盘价_3天均值']])
# print(df['收盘价'].rolling(3).max())
# print(df['收盘价'].rolling(3).min())
# print(df['收盘价'].rolling(3).std())

# df['收盘价_至今均值'] = df['收盘价'].expanding().mean()
# print(df[['收盘价', '收盘价_至今均值']])

# expanding即为取从头至今的数据。后面可以接各类计算函数
# print(df['收盘价'].expanding().max())
# print(df['收盘价'].expanding().min())
# print(df['收盘价'].expanding().std())

# print(df)
df.to_csv('output.csv', encoding='gbk', index=False)